// Scoring M2M nostra

#include <ScoringM2M.h>

namespace Biopool
{

// CONSTRUCTORS:

ScoringM2M::ScoringM2M(SubMatrix *sub, AlignmentData *ad, Structure *str,
	Profile *pro1, Profile *pro2, ScoringFunction *fun, double cSeq)
		: ScoringScheme(sub, ad, str), seq1(ad->getSequence(1)),
			seq2(ad->getSequence(2)), pro1(pro1), pro2(pro2), fun(fun),
				cSeq(cSeq)
{ }


ScoringM2M::ScoringM2M(const ScoringM2M &orig) : ScoringScheme(orig)
{
	copy(orig);
}


ScoringM2M::~ScoringM2M()
{ }


// OPERATORS:

ScoringM2M&
ScoringM2M::operator = (const ScoringM2M &orig)
{
	if (&orig != this)
		copy(orig);
	return *this;
}


// PREDICATES:

double
ScoringM2M::scoring(int i, int j)
{
	double s = cSeq * fun->scoringSeq(i, j);

	if (str != 0)
		s += str->scoringStr(i, j);

	return s;
}


// MODIFIERS:

void
ScoringM2M::copy(const ScoringM2M &orig)
{
	ScoringScheme::copy(orig);
	seq1 = orig.seq1;
	seq2 = orig.seq2;
	pro1 = orig.pro1->newCopy();
	pro2 = orig.pro2->newCopy();
	fun = orig.fun->newCopy();
	cSeq = orig.cSeq;
}


ScoringM2M*
ScoringM2M::newCopy()
{
	ScoringM2M *tmp = new ScoringM2M(*this);
	return tmp;
}


void
ScoringM2M::reverse()
{
	ScoringScheme::reverse();

	string tmp = "";
	for (unsigned int i = seq2.length(); i > 0; i--)
		tmp.push_back(seq2[i-1]);
	seq2 = tmp;

	pro2->reverse();
}

} // namespace
